package com.inspur.ourhis_afterend.Controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inspur.ourhis_afterend.Service.PrescribeService;
import com.inspur.ourhis_afterend.Tools.PageAction;
import com.inspur.ourhis_afterend.Tools.Result;

import com.inspur.ourhis_afterend.vo.PrescribeVo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/prescribe")
public class PrescribeController {
    @Resource(name = "prescribeServiceImpl")
    PrescribeService prescribeService;

    @ApiOperation("按条件动态查询")
    @ApiParam(value = "传入任意条件")
    @PostMapping("/findAllDrugs")
    public Result findAllM(@RequestBody PageAction pageAction,
                           @RequestParam(value = "memeberid",required = false) String memeberid,
                           @RequestParam(value = "roid",required = false) String roid){
        IPage<PrescribeVo> page = new Page<>(pageAction.getPageNo(),pageAction.getPageSize());
        try {
            return Result.success(prescribeService.findByMandRid(page,memeberid, roid));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }

    @ApiOperation("获取开药信息")
    @ApiParam(value = "传入开药表id")
    @GetMapping("selectByRoid")
    public Result selectByRoid(@RequestParam("roid") Integer roid){
        try {
            return Result.success(prescribeService.findByRoid(roid));
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }
    @ApiOperation("发药状态修改")
    @ApiParam(value = "传入开药表id")
    @PostMapping("/updateStatus")
    public Result updateStatus(@RequestParam("prescribeid")Integer prescribeid ){
        try {
            prescribeService.updateByRoid(prescribeid);
            return Result.success("成功");
        } catch (Exception e) {
            e.printStackTrace();
            return Result.failure(e.toString());
        }
    }
}
